package cn.wokoba.service.activity.service.state.handler.event;

import cn.wokoba.service.activity.model.ActivityStateVO;
import cn.wokoba.service.activity.service.state.handler.AbstractActivityState;
import cn.wokoba.types.enums.ResponseCode;
import cn.wokoba.types.exception.AppException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component("passState")

@Slf4j
public class PassState extends AbstractActivityState {
    @Override
    public boolean check(Long activityId, ActivityStateVO currentStatus) {
        log.error("过审状态不可重复审核 activityId:{}", activityId);
        throw new AppException(ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getCode(),ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getInfo());
    }

    @Override
    public boolean pass(Long activityId, ActivityStateVO currentStatus) {
        log.error("过审状态不可重复过审 activityId:{}", activityId);
        throw new AppException(ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getCode(),ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getInfo());
    }

    @Override
    public boolean closed(Long activityId, ActivityStateVO currentStatus) {
        activityRepository.alterActivityState(activityId, currentStatus.getCode(), ActivityStateVO.close.getCode());
        return true;
    }

    @Override
    public boolean create(Long activityId, ActivityStateVO currentStatus) {
        log.error("过审状态不可重复创建 activityId:{}", activityId);
        throw new AppException(ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getCode(),ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getInfo());
    }

    @Override
    public boolean open(Long activityId, ActivityStateVO currentStatus) {
        activityRepository.alterActivityState(activityId, currentStatus.getCode(), ActivityStateVO.open.getCode());
        return true;
    }

    @Override
    public Enum<ActivityStateVO> getTypeEnum() {
        return ActivityStateVO.pass;
    }
}
